package com.exam.controller;

import com.exam.entity.Admin;
import com.exam.entity.ApiResult;
import com.exam.serviceimpl.AdminServiceImpl;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = {"/admincontroller"})
public class AdminController {

    private AdminServiceImpl adminService;
    @Autowired
    public AdminController(AdminServiceImpl adminService){
        this.adminService = adminService;
    }

    @RequestMapping("/findAllAdmins")
    public ResponseEntity<List<Admin>> findAll(){
        System.out.println("查询全部");
        return new ResponseEntity<List<Admin>>(this.adminService.findAll(), HttpStatus.OK);
    }

    @RequestMapping("/findByIdAdmin/{adminId}")
    public ResponseEntity<Admin> findById(@PathVariable("adminId") Integer adminId){
        System.out.println("根据ID查找");

        return new ResponseEntity<Admin>(this.adminService.findById(adminId),HttpStatus.OK);
    }

    @RequestMapping("/deleteByIdAdmin/{adminId}")
    public ResponseEntity<Integer> deleteById(@PathVariable("adminId") Integer adminId){
        return  new ResponseEntity<Integer>(this.adminService.deleteById(adminId),HttpStatus.OK);

    }

    @RequestMapping("/updateAdmin/{adminId}")
    public ResponseEntity<Integer> update(@PathVariable("adminId") Integer adminId, Admin admin){
        return new ResponseEntity<Integer>(this.adminService.update(admin),HttpStatus.OK);
    }

    @RequestMapping("/admin")
    public ResponseEntity<Integer> add(Admin admin){
        return new ResponseEntity<Integer>(this.adminService.add(admin),HttpStatus.OK);
    }
}
